#include<bits/stdc++.h>
using namespace std;

map<string, string> stock;
map<string, string> cache;

bool readstock() {
  string buf;
  getline(cin,buf); // No '\n' included.
  if(buf == "END")return false;

  stock.insert({buf.substr(1,buf.rfind('"')-1),
    buf.substr(buf.find(" by ")+sizeof(" by ")-1)});

  return true;
}

bool query() {
  string op;cin>>op;
  if(op=="SHELVE") {

  }
  else {
    if(op=="BORROW") {
      string tt;cin>>tt;
      tt = tt.substr(1, tt.size()-1);
      cache.insert(*stock.find(tt));
    }
    else if(op=="RETURN") {
      string tt;
    }
  }
}

void solve() {
  while(readstock())continue;
  while(query())continue;
  return;
}

int main() {
  solve();
  return 0;
}